<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js闭包之应用场景示例(获取数组区间)</title>
</head>
<body>
  <script>
    const arr = [1, 2, 3, 4, 5, 6, 7, 8]
    let between = function(a, b) {
      return function(item) {
        return item >= a && item <= b
      }
    }
    console.log(arr.filter(between(2, 5))) // [2, 3, 4, 5]
    const cart = [
      { name: 'iphone', price: 8000 },
      { name: 'imac', price: 12000 },
      { name: 'ipad', price: 3688 }
    ]
    between = function(a, b) {
      return function(item) {
        return item.price >= a && item.price <= b
      }
    }
    console.table(cart.filter(between(8000, 12000)))
  </script>
</body>
</html>